package com.ali.ttt.netty.server.listener;

import com.ali.ttt.netty.common.domain.*;
import com.ali.ttt.netty.common.intface.InMessage;
import com.ali.ttt.netty.common.utils.MessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


/**
 * @author yuxl
 */
@Slf4j
@Component
public class ServerListener {
    @InMessage(path="/api",name = "调用api")
    public void api(Message<ApiMessage> req){
        ServerSession session = req.getCtx().channel().attr(ServerSession.SESSION_KEY).get();
        log.info("session:{}:{}调用api,发送数据:{}",session.getClient().getHost(),session.getClient().getProd(),req.getMsg().getMsg());
    }

    @InMessage(path="/login",name = "登录回调")
    public void login(Message<Client> req){
        Client msg = req.getMsg();
        log.info("调用login=>host:{},prod:{}",msg.getHost(),msg.getProd());
        MessageUtil.send(req.getCtx(),req);
    }
}
